<template>
  <div class="section_common">
    <div class="main">
      <el-form ref="form" label-width="100px">
        <el-form-item label="姓名" required>
          <el-input v-model="name" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="电话" required>
          <el-input v-model="phone" size="mini" @change="findUser($event)"></el-input>
        </el-form-item>
        <el-form-item label="招聘负责人">
          <el-input v-model="uploadName" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="面试时间">
          <el-date-picker
            size="mini"
            v-model="interviewTime"
            type="datetime"
            placeholder="选择日期"
            :editable="false"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="简历来源">
          <el-select v-model="resumeSource" size="mini" placeholder="请选择">
            <el-option label="BOSS直聘" value="BOSS直聘"></el-option>
            <el-option label="拉钩" value="拉钩"></el-option>
            <el-option label="智联招聘" value="智联招聘"></el-option>
            <el-option label="前程无忧" value="前程无忧"></el-option>
            <el-option label="猎聘" value="猎聘"></el-option>
            <el-option label="内推" value="内推"></el-option>
            <el-option label="其他" value="其他"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工作时长">
          <el-input v-model="workHours" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="学历">
          <el-select v-model="educational" size="mini" placeholder="请选择">
            <el-option label="小学" value="小学"></el-option>
            <el-option label="中学" value="中学"></el-option>
            <el-option label="中专" value="中专"></el-option>
            <el-option label="大专" value="大专"></el-option>
            <el-option label="本科" value="本科"></el-option>
            <el-option label="研究生" value="研究生"></el-option>
            <el-option label="博士" value="博士"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="毕业院校">
          <el-input v-model="graduate" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="专业">
          <el-input v-model="professional" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="最近工作公司">
          <el-input v-model="recentCompany" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="工作岗位">
          <el-input v-model="jobs" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="初试评价">
          <el-input type="textarea" v-model="firstEvaluation" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="复试评价">
          <el-input type="textarea" v-model="secondEvaluation" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="isThrough" size="mini" placeholder="请选择">
            <el-option label="待复试" value="待复试"></el-option>
            <el-option label="复试通过" value="复试通过"></el-option>
            <el-option label="复试未通过" value="复试未通过"></el-option>
            <el-option label="未通过" value="未通过"></el-option>
            <el-option label="已通过" value="已通过"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="评估意见">
          <el-input type="textarea" v-model="assessment" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="评估人">
          <el-input v-model="evaluator" size="mini"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="submitPost"
            >提交</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import {Dialog, Toast} from "vant";
export default {
  data() {
    return {
      id:"",
      name:"",
      phone:"",
      interviewTime:"",
      resumeSource:"",
      workHours:"",
      firstEvaluation:"",
      secondEvaluation:"",
      assessment:"",
      evaluator:"",
      educational:"",
      graduate:"",
      professional:"",
      recentCompany:"",
      jobs:"",
      uploadPerson:"",//招聘负责人
      uploadName:"",
      isThrough:"",

      nowUser: '',
      title: "面试登记",
      interviewTimeShow:false,
      currentDate:new Date(),

      updateInterview: '/mobiles/updateInterview',
      code:"",

    };
  },
  created() {
    this.nowUser=JSON.parse(localStorage.getItem('userInfo')).userId;
  },
  activated() {
    this.isPermissionqx();
  },
  methods: {
    //指定角色的用户才能操作
    isPermissionqx(){
      this.$https.post('/mobiles/isPermissionqx', {
        userId:this.nowUser,
        zdRname:"招聘组"
      }).then((res)=>{
        if (res.data.code=='500'){
          Dialog.alert({
            message: res.data.message,
          }).then(() => {
            this.$router.go(-1);
          });
        }

      }).catch(err => {
        console.log(err);
      });
    },
    // 根据用户姓名和电话查询对应的面试信息
    findUser(){
      if (this.name=='' || this.phone==''){
        this.$toast("姓名或电话不能为空");
        this.name='';
        this.phone='';
        return false;
      }
      this.$https.post('/mobiles/findInterviewUser',{
        userId:this.nowUser,
        name:this.name,
        phone: this.phone
      }).then((res)=>{
        if (res.data.code=='500'){
          this.code=500;
          this.$toast(res.data.message);
        }else {
          this.code='';
        }
        if (res.data.code=='200'){
          this.id=res.data.data.data.id;
          this.interviewTime=res.data.data.data.interviewTime;
          this.uploadPerson=res.data.data.data.uploadPerson;
          this.uploadName=res.data.data.uploadName;
          this.resumeSource=res.data.data.data.resumeSource;
          this.workHours=res.data.data.data.workHours;
          this.educational=res.data.data.data.educational;
          this.graduate=res.data.data.data.graduate;
          this.professional=res.data.data.data.professional;
          this.recentCompany=res.data.data.data.recentCompany;
          this.jobs=res.data.data.data.jobs;
          this.isThrough=res.data.data.data.isThrough;
          this.firstEvaluation=res.data.data.data.firstEvaluation;
          this.secondEvaluation=res.data.data.data.secondEvaluation;
          this.assessment=res.data.data.data.assessment;
          this.evaluator=res.data.data.data.evaluator;
        }

      }).catch(err=>{
        console.log(err);
      })
    },

    // 返回
    goBack() {
      this.$router.go(-1);
    },
    // 提交
    submitPost() {
      if (!this.isNull()) return false;
      /*var s = '';
      s = this.getImageUrl(s);*/
      // on confirm
      this.$https.post(this.updateInterview, {
        id:this.id,
        name:this.name,
        phone:this.phone,
        interviewTime:this.interviewTime,
        resumeSource:this.resumeSource,
        workHours:this.workHours,
        firstEvaluation:this.firstEvaluation,
        secondEvaluation:this.secondEvaluation,
        assessment:this.assessment,
        evaluator:this.evaluator,
        educational:this.educational,
        graduate:this.graduate,
        professional:this.professional,
        recentCompany:this.recentCompany,
        jobs:this.jobs,
        uploadPerson:this.uploadPerson,//招聘负责人
        uploadName:this.uploadName,
        isThrough:this.isThrough,

      }).then(() => {
        Toast("推送成功");
        this.$router.go(-1);
      }).catch(err => {
        console.log(err)
      });
    },
    //判断相关数据是否为空
    isNull() {
      if (this.name == '') {
        this.$toast("姓名不能为空");
        return false;
      }
      if (this.phone == '') {
        this.$toast("电话不能为空");
        return false;
      }
      if (this.interviewTime == '') {
        this.$toast("面试时间不能为空");
        return false;
      }
      if (this.uploadPerson == '') {
        this.$toast("招聘负责人不能为空");
        return false;
      }
      if (this.code=='500'){
        this.$toast("无权进行面试登记操作");
        return false;
      }
      return true;
    },

  },
};
</script>

<style lang="scss" scoped>
.main {
  display: flex;
  justify-items: center;
  margin: 0 auto;
  .el-form {
    padding-right: 10px;
    .el-form-item {
      .el-form-item__label {
        line-height: 16px;
      }
      margin-bottom: 5px;
    }
  }
}
</style>